package master;

/**
 * @author chenyw
 * @date 2022/7/27 17:31
 */
public class M125isPalindrome {
    public static void main(String[] args) {
        boolean b = new M125isPalindrome().isPalindrome("::");
        System.out.println(b);

        char c = 3;
        char y = 4;
        System.out.println(c == y);
        System.out.println(Character.toLowerCase(c));
        System.out.println(c == y);
        char x = 'a';
        System.out.println(Character.toUpperCase(x));
    }
    public boolean isPalindrome(String s) {
        int i = 0;
        int j = s.length() - 1;
        while (i <= j) {
            while (i <= s.length() - 1 && !Character.isDigit(s.charAt(i)) && !Character.isLetter(s.charAt(i))) {
                i++;
            }
            while (j >= 0 &&!Character.isDigit(s.charAt(j)) && !Character.isLetter(s.charAt(j))) {
                j--;
            }
            if (i > j) {
                return true;
            }
            if (Character.isDigit(s.charAt(i)) && Character.isDigit(s.charAt(j))) {
                if (s.charAt(i) != s.charAt(j)) {
                    return false;
                }
            } else if (Character.isLetter(s.charAt(i)) && Character.isLetter(s.charAt(j))) {
                char c = Character.toUpperCase(s.charAt(i));
                char c1 = Character.toUpperCase(s.charAt(j));
                if (c != c1) {
                    return false;
                }
            } else {
                return false;
            }

            i++;
            j--;

        }
        return true;
    }
}
